﻿/*
 * Crée par SharpDevelop.
 * Utilisateur: ngr
 * Date: 19/02/2015
 * Heure: 14:54
 * 
 * Pour changer ce modèle utiliser Outils | Options | Codage | Editer les en-têtes standards.
 */
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;


using Compta.Core.Classes;
using Compta.Core.Structures;
using Compta.Core;

namespace ComptaPerso.Controls
{
	/// <summary>
	/// Description of UC_Home.
	/// </summary>
	public partial class UC_Home : UserControl
	{
		
		ComptaCore core;
		MainForm m;
		
		public UC_Home(MainForm m, ComptaCore core)
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			
			//
			// TODO: Add constructor code after the InitializeComponent() call.
			//
			this.m = m;
			this.core = core;
			
			LoadAccounts();
			
		}
		
		
		/// <summary>
		/// Affichage des comptes
		/// </summary>
		public void LoadAccounts()
		{
			foreach(Account a in core.ListAccounts){
				ListViewItem lvi = new ListViewItem(a.Id.ToString());
				lvi.SubItems.Add(a.Name);
				lvi.SubItems.Add(a.BalanceReal.ToString());
				lvi.SubItems.Add(a.Owner);
				
				LvwAccounts.Items.Add(lvi);
			}
					
		}
		
		
		/// <summary>
		/// 
		/// </summary>
		public void LoadNextAutoOp()
		{
			
		}
		
		
		void LvwAccountsMouseDoubleClick(object sender, MouseEventArgs e)
		{
			OpenSelectedAccount();
		}
		
		void OpenSelectedAccount()
		{
			ListViewItem lvi = LvwAccounts.SelectedItems[0];
			int id = Convert.ToInt32(lvi.SubItems[0].Text);
			
			UC_Account a = new UC_Account(m, id);
			m.AddPanel2Controls(a);
			
		}
	}
}
